package com.example.studyonlineapplication.utils;

import static androidx.viewpager.widget.PagerAdapter.POSITION_NONE;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.example.studyonlineapplication.fragments.NoteTabFragment;


public class NoteViewPagerAdapter extends FragmentStateAdapter {
    private final int NUM_TABS = 2; // 设置选项卡数量
    private String data;
    private NoteTabFragment noteTabFragment0,noteTabFragment1;
    private FragmentActivity fragmentActivity;

    public NoteViewPagerAdapter(@NonNull FragmentActivity fragmentActivity,String data) {
        super(fragmentActivity);
        this.fragmentActivity = fragmentActivity;
        this.data = data;
    }
    public NoteViewPagerAdapter(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
        this.fragmentActivity = fragmentActivity;

    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        Bundle bundle =new Bundle();
        bundle.putInt("state", position);
        bundle.putString("seCond",data);
        if (position==0){
            if (noteTabFragment0==null){
                noteTabFragment0 = new NoteTabFragment();
                noteTabFragment0.setArguments(bundle);
            }
            return noteTabFragment0;
        }
        else{
            if (noteTabFragment1==null){
                noteTabFragment1 = new NoteTabFragment();
                noteTabFragment1.setArguments(bundle);
            }
            return noteTabFragment1;
        }




    }



    @Override
    public int getItemCount() {
        return NUM_TABS; // 返回选项卡数量
    }



}
